package com.huawei.appgallery.forum.posts.view;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.util.SparseArray;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import com.huawei.appgallery.forum.base.card.bean.User;
import com.huawei.appgallery.forum.base.https.jgw.JGWTabDetailResponse;
import com.huawei.appgallery.forum.base.ui.JGWTabFragment;
import com.huawei.appgallery.forum.cards.bean.ForumTitleSortCardBean;
import com.huawei.appgallery.forum.posts.card.ForumTopicCommentCardBean;
import com.huawei.appgallery.foundation.account.bean.UserSession;
import com.huawei.appgallery.foundation.ui.framework.cardframe.bean.BaseDetailResponse.LayoutData;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.hmf.annotation.FragmentDefine;
import java.util.List;
import o.bqx;
import o.bre;
import o.brz;
import o.bse;
import o.bsl;
import o.bsv;
import o.buk;
import o.byg;
import o.bzn;
import o.bzu;
import o.cbc;
import o.cbd;
import o.cia;
import o.CollectCheck;
import o.evr;
import o.fho;
import o.ll;

@FragmentDefine(alias = "post.detail.fragment", protocol = IPostDetailFrgProtocol.class)
public class PostDetailFragment extends JGWTabFragment {
    private BroadcastReceiver ʳ = new c();
    private boolean ʹॱ;
    private int ʻʻ = -1;
    private Handler ʻʼ = new Handler();
    private View ʻʽ;
    private int ʻˊ = 0;
    IntentFilter ʻˋ = new IntentFilter();
    private bzn ʼˋ;
    private int ꜝ;
    private int ꜞॱ;
    private SparseArray ꜟॱ = new SparseArray(0);
    private buk ꞌॱ;
    private bzu ﹳॱ;
    private BroadcastReceiver ﹶ = new b();
    private int ﹺ;
    int ﾞ;
    private int ﾞॱ = -1;
    private int ﾟॱ = -1;

    class b extends BroadcastReceiver {
        final /* synthetic */ PostDetailFragment ˎ;

        private b(PostDetailFragment postDetailFragment) {
            this.ˎ = postDetailFragment;
        }

        public void onReceive(Context context, Intent intent) {
            if (intent != null) {
                String action = intent.getAction();
                bqx.ˏ("PostDetailFragment", "PostDetailReceiver:" + action);
                if ("com.huawei.appgallery.forum.posts.refreshlist".equals(action)) {
                    this.ˎ.ॱـ();
                } else if ("com.huawei.appgallery.forum.posts.deletecomment".equals(action)) {
                    this.ˎ.ˊ(intent.getLongExtra("comment_id", 0));
                }
            }
        }
    }

    class c extends BroadcastReceiver {
        final /* synthetic */ PostDetailFragment ॱ;

        private c(PostDetailFragment postDetailFragment) {
            this.ॱ = postDetailFragment;
        }

        public void onReceive(Context context, Intent intent) {
            if (intent != null) {
                String action = intent.getAction();
                bqx.ˏ("PostDetailFragment", "SortReceiver:" + action);
                if ("forum.comments.list.refresh".equals(action)) {
                    evr.ˊ().ᐝ();
                    this.ॱ.ͺ(intent.getIntExtra("notify_type", -1));
                }
            }
        }
    }

    static class e {
        int ˋ = 0;
        int ॱ = 0;

        e() {
        }
    }

    public void ˏ(Bundle bundle) {
        bre.ॱ.ॱ("time_0002_");
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.huawei.appgallery.forum.posts.refreshlist");
        intentFilter.addAction("com.huawei.appgallery.forum.posts.deletecomment");
        this.ʻˋ.addAction("forum.comments.list.refresh");
        ॱˑ();
        ॱˉ();
        Context ॱˊ = ॱˊ();
        if (ॱˊ != null) {
            ll.ˏ(ॱˊ).ˏ(this.ﹶ, intentFilter);
        }
        super.ˏ(bundle);
    }

    public void ˎˎ() {
        super.ˎˎ();
        Context ॱˊ = ॱˊ();
        if (ॱˊ != null) {
            ll.ˏ(ॱˊ).ˋ(this.ﹶ);
        }
    }

    public void ag_() {
        super.ag_();
        Context ॱˊ = ॱˊ();
        if (ॱˊ != null) {
            ll.ˏ(ॱˊ).ˏ(this.ʳ, this.ʻˋ);
        }
    }

    public void ʼ() {
        super.ʼ();
        Context ॱˊ = ॱˊ();
        if (ॱˊ != null) {
            ll.ˏ(ॱˊ).ˋ(this.ʳ);
        }
    }

    private boolean ˏ(com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b bVar) {
        return bVar.ˋ.getResponseCode() == 0 && bVar.ˋ.getRtnCode_() == 0 && (bVar.ˋ instanceof JGWTabDetailResponse);
    }

    public boolean ˊ(TaskFragment taskFragment, com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment.b bVar) {
        boolean ˊ = super.ˊ(taskFragment, bVar);
        if (ʼʼ() != null) {
            ʼʼ().ˋ(taskFragment, bVar);
        }
        if (!(this.ﾟॱ == -1 || this.ﾞॱ == -1)) {
            this.ͺˎ.setSelectionFromTop(this.ﾟॱ, this.ﾞॱ - this.ꜝ);
            this.ﾟॱ = -1;
            this.ﾞॱ = -1;
        }
        if (ˏ(bVar)) {
            Object obj;
            JGWTabDetailResponse jGWTabDetailResponse = (JGWTabDetailResponse) bVar.ˋ;
            List<LayoutData> ᐝॱ = jGWTabDetailResponse.ᐝॱ();
            if (CollectCheck.isEmpty((List) ᐝॱ)) {
                obj = null;
            } else {
                for (LayoutData layoutData : ᐝॱ) {
                    if ((ForumTopicCommentCardBean.NAME.equals(layoutData.ˏ()) || ForumTitleSortCardBean.NAME.equals(layoutData.ˏ())) && !CollectCheck.isEmpty(layoutData.ˋ())) {
                        obj = 1;
                        break;
                    }
                }
                obj = null;
                if (obj != null) {
                    ˎ(ᐝॱ);
                    ˎ(jGWTabDetailResponse, ᐝॱ);
                }
            }
            if (obj == null && this.ʼˋ != null) {
                this.ʼˋ.ˊ();
            }
            if (ॱˋ() instanceof PostDetailActivity) {
                ((PostDetailActivity) ॱˋ()).ˏ(jGWTabDetailResponse.ᐝ());
            }
        }
        bre.ॱ.ˊ("time_0002_");
        return ˊ;
    }

    private void ˎ(JGWTabDetailResponse jGWTabDetailResponse, List<LayoutData> list) {
        if (jGWTabDetailResponse.ʻ() > 0) {
            for (LayoutData layoutData : list) {
                if (ForumTopicCommentCardBean.NAME.equals(layoutData.ˏ())) {
                    for (ForumTopicCommentCardBean ˎ : layoutData.ˋ()) {
                        ˎ.ˎ(jGWTabDetailResponse.ʻ());
                    }
                }
            }
        }
    }

    private void ˎ(List<LayoutData> list) {
        if (this.ʹॱ) {
            if (list != null && list.size() > 0) {
                int i = 0;
                for (LayoutData layoutData : list) {
                    int size;
                    if (!CollectCheck.isEmpty(layoutData.ˋ())) {
                        if (ForumTopicCommentCardBean.NAME.equals(layoutData.ˏ()) || ForumTitleSortCardBean.NAME.equals(layoutData.ˏ())) {
                            break;
                        }
                        size = layoutData.ˋ().size() + i;
                    } else {
                        size = i;
                    }
                    i = size;
                }
                if (i > 0 && this.ͺˎ != null) {
                    this.ͺˎ.setVisibility(4);
                    this.ʻʼ.post(new Runnable(this) {
                        final /* synthetic */ PostDetailFragment ˏ;

                        public void run() {
                            this.ˏ.ͺˎ.setVisibility(0);
                            this.ˏ.ͺˎ.setSelectionFromTop(i, 0);
                        }
                    });
                }
            }
            this.ʹॱ = false;
        }
    }

    public View ˋ(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        super.ˋ(layoutInflater, viewGroup, bundle);
        if (this.ͺˎ != null) {
            this.ͺˎ.setPadding(0, this.ꜝ, 0, 0);
            this.ͺˎ.setClipToPadding(false);
        }
        if (this.ﾞ > 0) {
            ˋॱ(false);
        }
        this.ʻʽ = this.ॱˍ.findViewById(o.bzd.b.ᐧ);
        return this.ॱˍ;
    }

    public cia ˊ(Context context) {
        this.ʼˋ = new bzn(context);
        return this.ʼˋ;
    }

    private void ॱˑ() {
        try {
            IPostDetailFrgProtocol iPostDetailFrgProtocol = (IPostDetailFrgProtocol) this.ﹳ.ॱ();
            this.ʼˊ = iPostDetailFrgProtocol.getUri();
            this.ꜝ = iPostDetailFrgProtocol.getPaddingTop();
            this.ﾞ = iPostDetailFrgProtocol.getErrorCode();
            this.ʼ = new bsl(this, null, this.ʼˊ, bsv.ॱ(iPostDetailFrgProtocol.getDomainId()));
            this.ʹॱ = iPostDetailFrgProtocol.getPositionToCommentCard();
        } catch (Exception e) {
            bqx.ˋ("PostDetailFragment", "init data exception");
        }
    }

    private void ॱˉ() {
        bqx.ˏ("PostDetailFragment", "mErrorCode:" + this.ﾞ);
        if (this.ﾞ > 0) {
            brz ॱ = bse.ˏ.ॱ(this.ﾞ);
            ʻ(ॱ.ˋ());
            ʼ(ॱ.ˎ());
            ˏॱ(false);
            return;
        }
        ʻ(o.bzd.e.ʽॱ);
        ʼ(bse.ˏ.ॱ(400001).ˎ());
    }

    public void ॱʾ() {
        if (this.ʻʻ > 0) {
            this.ͺˎ.setSelection(this.ʻʻ);
            this.ʻʻ = -1;
        }
    }

    public void ˎ(byg o_byg, int i, int i2, int i3) {
        User user = new User();
        user.ˎ(UserSession.getInstance().getUserName());
        user.ˋ(UserSession.getInstance().getHeadUrl());
        user.ॱ(1);
        user.ˏ(i2);
        user.ˋ(i3);
        cbc ˊ = ((cbd) fho.ˏ().ˋ("User").ॱ(cbd.class)).ˊ();
        if (ˊ != null) {
            user.ˊ(ˊ.ˎ());
            user.ˏ(ˊ.ˏ());
        }
        if (this.ʼˋ != null) {
            int ˊ2 = this.ʼˋ.ˊ(user, o_byg, this.ﾟ, i);
            this.ʼˋ.ͺ();
            this.ʻʻ = ˊ2;
        }
    }

    public void ˊ(long j) {
        if (this.ʼˋ != null) {
            this.ʼˋ.ˏ(j);
            this.ʼˋ.ͺ();
        }
    }

    public void ॱـ() {
        if (this.ʼˋ != null) {
            this.ʼˋ.ͺ();
        }
    }

    private void ͺ(int i) {
        int i2 = 0;
        if (i >= 0 && this.ꞌॱ != null && this.ꞌॱ.ˎ() == i) {
            String str = this.ʼˊ;
            if (i == 1) {
                str = this.ʼˊ + ",sort_0";
            } else if (i == 0) {
                str = this.ʼˊ + ",sort_1";
            }
            this.ﾟॱ = this.ͺˎ.getFirstVisiblePosition();
            View childAt = this.ͺˎ.getChildAt(0);
            if (childAt != null) {
                i2 = childAt.getTop();
            }
            this.ﾞॱ = i2;
            ॱॱ(str);
            ˎͺ();
        }
    }

    private void ˋ(AbsListView absListView, int i) {
        int ॱˌ;
        int i2 = 0;
        this.ʻˊ = i;
        View childAt = absListView.getChildAt(0);
        if (childAt != null) {
            e eVar = (e) this.ꜟॱ.get(i);
            if (eVar == null) {
                eVar = new e();
            }
            eVar.ॱ = childAt.getHeight();
            eVar.ˋ = childAt.getTop();
            this.ꜟॱ.append(i, eVar);
            ॱˌ = ॱˌ();
        } else {
            ॱˌ = 0;
        }
        int top = childAt == null ? 0 : childAt.getTop();
        if (i > this.ꜞॱ) {
            i2 = 1;
        } else if (i < this.ꜞॱ) {
            i2 = -1;
        } else if (top < this.ﹺ) {
            i2 = 1;
        } else if (top > this.ﹺ) {
            i2 = -1;
        }
        this.ꜞॱ = i;
        this.ﹺ = top;
        if (this.ﹳॱ != null) {
            this.ﹳॱ.ॱ(ॱˌ, i2);
        }
    }

    private int ॱˌ() {
        e eVar;
        int i = 0;
        for (int i2 = 0; i2 < this.ʻˊ; i2++) {
            eVar = (e) this.ꜟॱ.get(i2);
            if (eVar != null) {
                i += eVar.ॱ;
            }
        }
        eVar = (e) this.ꜟॱ.get(this.ʻˊ);
        if (eVar == null) {
            eVar = new e();
        }
        return i - eVar.ˋ;
    }

    public void ॱ(Context context) {
        super.ॱ(context);
        if (context instanceof bzu) {
            this.ﹳॱ = (bzu) context;
        }
        if (context instanceof buk) {
            this.ꞌॱ = (buk) context;
        }
    }

    public void onScroll(AbsListView absListView, int i, int i2, int i3) {
        super.onScroll(absListView, i, i2, i3);
        ˋ(absListView, i);
    }

    public void onScrollStateChanged(AbsListView absListView, int i) {
        super.onScrollStateChanged(absListView, i);
        if (this.ﹳॱ != null) {
            this.ﹳॱ.ˋ(absListView, i);
        }
    }

    public void ˑॱ() {
    }

    public void ˏͺ() {
    }

    public void ٴ() {
        super.ٴ();
        if (this.ʻʽ != null) {
            this.ʻʽ.setVisibility(8);
        }
    }
}
